import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/25 14:54
 * @description 模拟
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minimumDeletions(int[] nums) {
        int n = nums.length;
        int  maxIndex = 0,  minIndex = 0;
        for (int i = 1; i < n; i++) {
            if (nums[i] > nums[maxIndex]) {
                maxIndex = i;
            }
            if (nums[i] < nums[minIndex]) {
                minIndex = i;
            }
        }
        int a = Math.min(maxIndex, minIndex), b = Math.max(maxIndex, minIndex);
        int ans = a + 1 + n - b;
        ans = Math.min(ans, Math.min(b + 1, n - a));
        return ans;
    }
}
